package cn.admobiletop.adsuyi.adapter.gdt;

import com.qq.e.comm.managers.GDTADManager;
import com.qq.e.comm.managers.GDTAdSdk;
import com.qq.e.comm.managers.setting.GlobalSetting;

import java.util.Arrays;
import java.util.List;

import cn.admobiletop.adsuyi.ADSuyiSdk;

import cn.admobiletop.adsuyi.ad.adapter.ADSuyiAdapterIniter;
import cn.admobiletop.adsuyi.ad.adapter.ADSuyiAdapterIniterExtParams;
import cn.admobiletop.adsuyi.ad.adapter.ADSuyiAdapterLoader;
import cn.admobiletop.adsuyi.ad.data.ADSuyiAdType;
import cn.admobiletop.adsuyi.ad.data.ADSuyiPlatform;
import cn.admobiletop.adsuyi.adapter.gdt.loader.BannerAdLoader;
import cn.admobiletop.adsuyi.adapter.gdt.loader.FullScreenVodAdLoader;
import cn.admobiletop.adsuyi.adapter.gdt.loader.InterstitialAdLoader;
import cn.admobiletop.adsuyi.adapter.gdt.loader.NativeAdLoader;
import cn.admobiletop.adsuyi.adapter.gdt.loader.RewardVodAdLoader;
import cn.admobiletop.adsuyi.adapter.gdt.loader.SplashAdLoader;
import cn.admobiletop.adsuyi.config.ADSuyiInitConfig;

/**
 * @author ciba
 * @description 广点通平台初始化类
 * @date 2020/3/25
 */
public class ADSuyiIniter implements ADSuyiAdapterIniter {
    private static final String[] SUPPORT_ADSUYI_SDK_VERSIONS = {"3.3.2.08201"};
    public static final String PLATFORM = "gdt";
    private static boolean inited = false;

    @Override
    public void init(ADSuyiPlatform platform, ADSuyiAdapterIniterExtParams extParams) {
        if (!inited && platform != null && platform.check()) {
            ADSuyiInitConfig config = ADSuyiSdk.getInstance().getConfig();
            // Suyi后台下发的appId
            String appId = platform.getAppId();
            // 是否同意隐私政策
            boolean isAgreePrivacyStrategy = config.isAgreePrivacyStrategy();
            // 设置广点通是否支持隐私政策
            GlobalSetting.setAgreePrivacyStrategy(isAgreePrivacyStrategy);
            // 广点通广告SDK初始化
            GDTAdSdk.init(ADSuyiSdk.getInstance().getContext(), appId);
            inited = true;
        }
    }

    @Override
    public boolean inited() {
        return inited;
    }

    @Override
    public ADSuyiAdapterLoader getSuyiAdapterLoader(String adType) {
        if (ADSuyiAdType.TYPE_SPLASH.equals(adType)) {
            return new SplashAdLoader();
        } else if (ADSuyiAdType.TYPE_BANNER.equals(adType)) {
            return new BannerAdLoader();
        } else if (ADSuyiAdType.TYPE_FLOW.equals(adType)) {
            return new NativeAdLoader();
        } else if (ADSuyiAdType.TYPE_REWARD_VOD.equals(adType)) {
            return new RewardVodAdLoader();
        } else if (ADSuyiAdType.TYPE_FULLSCREEN_VOD.equals(adType)) {
            return new FullScreenVodAdLoader();
        } else if (ADSuyiAdType.TYPE_INTERSTITIAL.equals(adType)) {
            return new InterstitialAdLoader();
        }
        return null;
    }

    @Override
    public List<String> getSupportADSuyiSdkVersions() {
        return Arrays.asList(SUPPORT_ADSUYI_SDK_VERSIONS);
    }

    @Override
    public String getAdapterVersion() {
        return BuildConfig.VERSION_NAME;
    }
}
